using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 模板应用服务接口
    /// 提供页面模板和邮件模板管理的业务逻辑
    /// </summary>
    public interface ITemplateAppService
    {
        /// <summary>
        /// 获取分页的模板列表
        /// </summary>
        /// <param name="query">查询参数</param>
        /// <returns>分页的模板列表</returns>
        Task<PagedResultDto<TemplateDto>> GetPagedListAsync(PagedQueryDto query);
        
        /// <summary>
        /// 根据类型获取模板列表
        /// </summary>
        /// <param name="type">模板类型</param>
        /// <returns>模板列表</returns>
        Task<List<TemplateDto>> GetByTypeAsync(string type);
        
        /// <summary>
        /// 根据分类获取模板列表
        /// </summary>
        /// <param name="category">模板分类</param>
        /// <returns>模板列表</returns>
        Task<List<TemplateDto>> GetByCategoryAsync(string category);
        
        /// <summary>
        /// 根据ID获取模板详情
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <returns>模板详情</returns>
        Task<TemplateDto?> GetByIdAsync(long id);
        
        /// <summary>
        /// 根据名称获取模板
        /// </summary>
        /// <param name="name">模板名称</param>
        /// <returns>模板信息</returns>
        Task<TemplateDto?> GetByNameAsync(string name);
        
        /// <summary>
        /// 创建模板
        /// </summary>
        /// <param name="dto">模板数据</param>
        /// <returns>创建的模板</returns>
        Task<TemplateDto> CreateAsync(TemplateDto dto);
        
        /// <summary>
        /// 更新模板
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <param name="dto">更新的模板数据</param>
        /// <returns>更新后的模板</returns>
        Task<TemplateDto> UpdateAsync(long id, TemplateDto dto);
        
        /// <summary>
        /// 删除模板
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <returns>删除结果</returns>
        Task<bool> DeleteAsync(long id);
        
        /// <summary>
        /// 批量删除模板
        /// </summary>
        /// <param name="ids">模板ID列表</param>
        /// <returns>删除结果</returns>
        Task<bool> BatchDeleteAsync(List<long> ids);
        
        /// <summary>
        /// 复制模板
        /// </summary>
        /// <param name="id">原模板ID</param>
        /// <param name="newName">新模板名称</param>
        /// <returns>复制的模板</returns>
        Task<TemplateDto> CopyAsync(long id, string newName);
        
        /// <summary>
        /// 渲染模板
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <param name="data">数据对象</param>
        /// <returns>渲染结果</returns>
        Task<string> RenderAsync(long id, object data);
        
        /// <summary>
        /// 渲染模板内容
        /// </summary>
        /// <param name="content">模板内容</param>
        /// <param name="data">数据对象</param>
        /// <param name="engine">模板引擎</param>
        /// <returns>渲染结果</returns>
        Task<string> RenderContentAsync(string content, object data, string engine = "razor");
        
        /// <summary>
        /// 验证模板语法
        /// </summary>
        /// <param name="content">模板内容</param>
        /// <param name="engine">模板引擎</param>
        /// <returns>验证结果</returns>
        Task<(bool IsValid, string[] Errors)> ValidateAsync(string content, string engine = "razor");
        
        /// <summary>
        /// 获取默认模板
        /// </summary>
        /// <param name="type">模板类型</param>
        /// <returns>默认模板</returns>
        Task<TemplateDto?> GetDefaultAsync(string type);
        
        /// <summary>
        /// 设置默认模板
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <returns>设置结果</returns>
        Task<bool> SetDefaultAsync(long id);
        
        /// <summary>
        /// 启用/禁用模板
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <param name="enabled">是否启用</param>
        /// <returns>操作结果</returns>
        Task<bool> SetEnabledAsync(long id, bool enabled);
        
        /// <summary>
        /// 更新使用次数
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <returns>更新结果</returns>
        Task<bool> IncrementUsageCountAsync(long id);
        
        /// <summary>
        /// 获取模板变量
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <returns>变量列表</returns>
        Task<Dictionary<string, object>> GetVariablesAsync(long id);
        
        /// <summary>
        /// 预览模板
        /// </summary>
        /// <param name="id">模板ID</param>
        /// <param name="data">预览数据</param>
        /// <returns>预览结果</returns>
        Task<string> PreviewAsync(long id, object? data = null);
        
        /// <summary>
        /// 导出模板
        /// </summary>
        /// <param name="ids">模板ID列表</param>
        /// <returns>导出数据</returns>
        Task<byte[]> ExportAsync(List<long> ids);
        
        /// <summary>
        /// 导入模板
        /// </summary>
        /// <param name="data">导入数据</param>
        /// <returns>导入结果</returns>
        Task<List<TemplateDto>> ImportAsync(byte[] data);
        
        /// <summary>
        /// 检查模板名称是否存在
        /// </summary>
        /// <param name="name">模板名称</param>
        /// <param name="excludeId">排除的模板ID</param>
        /// <returns>是否存在</returns>
        Task<bool> ExistsAsync(string name, long? excludeId = null);
    }
}
